<div class="row" style="margin-bottom: 20px; margin-top: -15px;">
    <div class="col-sm-12">
        <h3>
        	<i class="fa fa-edit" style="color:<?php echo $color?>"></i> <?php echo $title?>
        </h3>
    </div>
</div>
<div class="row" style="margin-bottom: 20px;">
    <div class="col-md-6">
        <div class="btn-group" id="bulk-action-container" style="display: none;">
            <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
                Bulk Actions  <span class="caret"></span>
            </button>
            <ul class="dropdown-menu" role="menu">
                <li><a href="#" onclick="bulk_action('delete'); return false;">Delete</a></li>
            </ul>
        </div>
    </div>
    <div class="col-md-4" style="height: 34px;">&nbsp;</div>
</div>
<div class="row" style="padding: 10px 0px;">
    <div class="col-md-6">
        <div class="btn-group">
            <button type="button" class="btn btn-default btn-sm btn-flat dropdown-toggle" data-toggle="dropdown">
                <span id="view-title">All</span>
                <span class="caret"></span>
            </button>
            <ul class="dropdown-menu" role="menu">
                <li><a href="<?php echo base_url('admin/users/index');?>"> All</a></li>
                <li><a href="javascript:view_allstatus(1,'published');"> Published</a></li>
                <li><a href="javascript:view_allstatus(2,'unpublished');"> Unpublished</a></li>
            </ul>
        </div>
    </div>
    <div class="col-md-6">
        <div class="pull-right">
            <div class="pull-right">
             	<div class="form-inline" id="pagingControl">
	            <div class="form-group">
                    <label for="Page">Page: </label>
                    <select class="page form-control" >
                        <option selected="selected" value="1">1</option> 
                        <option  value="2">2</option>         
                        <option  value="3">3</option>         
                    </select>
                    <input type="hidden" value="1" class="page-hidden">
                </div>
             </div>
          	</div>        
        </div>
    </div>
</div>
<div class="row">
    <div class="col-sm-12">
    	<form action="" method="post" id="frm-list">
    		<div class="table-responsive">
                <table  class="table table-bordered table-hover" >
                    <thead>
                        <tr>
                            <th style="width: 10px; background: #3c8dbc; color: white;">#</th>
                            <th style="width: 10px; background: #3c8dbc; color: white;"><input type="checkbox" id="check-all"></th>
                            <th style="width: 120px;background: #3c8dbc; color: white;">Tên tập phim</th>
                            <th style="width: 140px; background: #3c8dbc; color: white;">Liên kết</th>
                            <th style="width: 80px; background: #3c8dbc; color: white;">Server</th>
                            <th style="width: 100px; background: #3c8dbc; color: white;">Sub</th>
                            <th style="width: 50px; background: #3c8dbc; color: white;">Action</th>
                        </tr>   
                    </thead>
                    <tbody id="result">
                        <?php if($result != NULL){?>
                            <?php $stt = 1?>
                            <?php foreach($result as $value): ?>
                                <tr>
                                    <td><?php echo $stt++ ;?></td>
                                    <td><input type="checkbox" name="id[]" value="<?php echo (int)$value['epid'];?>"></td>
                                    <td><?php echo $value['epname']?></td>
                                    <td><?php echo cut($value['url'],100)?></td>
                                    <td><?php echo $server[$value['server']]?></td>
                                    <td><?php echo $value['sub']?></td>
                                    <td>
                                        <button class="btn btn-info btn-xs" onclick="Episode_Edit('<?php echo (int)$value["epid"] ?>',<?php echo $id_film;?>);" type="button">
                                            <i class="fa fa-pencil"></i>
                                        </button>
                                        <button class="btn btn-danger btn-xs" onclick="Episode_Delete('<?php echo (int)$value["epid"] ?>',<?php echo $id_film;?>);" type="button">
                                            <i class="fa fa-minus-circle"></i>
                                        </button>
                                    </td>
                                </tr>
                            <?php endforeach; ?>
                        <?php }else{ ?>
                            <tr>
                                <td  id="data_empty"><?php echo 'Không có dữ liệu!'?></td>
                            </tr>
                            <script>
                                $(document).ready(function(){
                                    $('#data_empty').attr('colspan',$('#frm-list  th').length).css({'text-align':'center'});
                                });
                            </script>
                        <?php } ?>
                    </tbody>
                </table>
                <ul class="pagination pull-right">
                    <?php echo $this->pagination->create_links();?>
                </ul>
            </div>
    	</form>
    </div>
</div>
<script>
    jQuery(document).ready(function($) {      
        $('.btn-index').css({display:'inline-block'});
        $('.btn-edit').css({display:'none'});
        $('.btn-copy').css({display:'none'});
        $('.btn-add').css({display:'none'});
        
        $('#check-all').on('ifChecked', function(event){
            $('input[name="id\[\]"]').iCheck('check');
            $('#bulk-action-container').show();
        });

        $('#check-all').on('ifUnchecked', function(event){
            $('input[name="id\[\]"]').iCheck('uncheck');
            $('#bulk-action-container').hide();
        });

        $('input[name="id\[\]"]').on('ifToggled', function(event){
            if ($('.content input[name="id\[\]"]:checked').length > 0){
                $('#bulk-action-container').show();
            }else{
                $('#bulk-action-container').hide();
                $('#check-all').iCheck('uncheck');
            }
        });
    });
    
    function Add(){
        var url = '<?php echo base_url("admin/category/add");?>';
        $(".content").mask("<?php echo 'Loading...'; ?>");
        window.location.href = url;
    }

    function Episode_Edit(id,f_id){
        $(".content").mask("<?php echo 'Loading...'; ?>");
        var url = '<?php echo base_url("admin/episode/edit");?>'+'/'+id+'/'+f_id;
        window.location.href = url;
    }

    function change_status(id,status){
        $(".content").mask("<?php echo 'Loading...'; ?>");
        var base_url = '<?php echo base_url("admin/category/change_status");?>'; 
        $.post(base_url,{action:true,id:id,status:status}, function(results) {
            $(".content").unmask();
            var html = '';
            if(status == 'publish'){
                html += "<a href=\"javascript:change_status("+id+",'unpublish');\" class=\"label label-success\">Published</a>";
            }else{
                html += "<a href=\"javascript:change_status("+id+",'publish');\" class=\"label label-danger\">Unpublished</a>"; 
            }
            $("#change-"+id).html(html);
        });
    }

    function Episode_Delete(id,f_id){
        $.sModal({
            image:'<?php echo base_url("assets/admin");?>/img/confirm.png',
            content:'<?php echo "Bạn có muốn xóa thể loại này"; ?>',
            animate:'fadeDown',
            buttons:[
                        {
                            text:'<i class="fa fa-times-circle"></i> Delete',
                            addClass:'btn-danger',
                            click:function(){
                                $(".content").mask("<?php echo 'Loading...'; ?>");
                                var url = '<?php echo base_url("admin/episode/delete");?>'+'/'+id+'/'+f_id;
                                window.location.href = url;
                            }
                        },
                        {
                            text:'Cancel',
                            click:function(id,data){
                                $.sModal('close',id);
                            }
                        },
                    ]
        });
    }
    

</script>